//移除链表元素  力扣203

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
	ListNode* removeElements(ListNode* head, int val) {
		//判断头结点
		while(head != NULL && head->val == val)
		{
			ListNode* tmp = head;
			head = head->next;
			delete tmp;
		}
		//判断其他节点
		ListNode* cur = head;
		while(cur != NULL && cur->next != NULL)
		{
			if(cur->next->val == val)
			{
				ListNode* tmp = cur->next;
				cur->next = cur->next->next;
				delete tmp;
			}
			else cur = cur->next;
		}
		return head;
	}
};
